var fs = require("fs");
var _ = require("lodash");

let fileNameC = "SkillConfig";
let fileName1 = "SkillDes";
let fileName2 = "BuffDes";
let outputFileName = "./data/skill3.json";

let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString()).map;
let skillDes = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString()).map;
let buffDes = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString()).map;

let skillMap = new Map();
let buffMap = new Map();
_.forEach(skillDes, (e) => {
  let id = e.id;
  let data = e.data;
  skillMap.set(id, data);
});
_.forEach(buffDes, (e) => {
  let id = e.id;
  let data = e.data;
  buffMap.set(id, data);
});
_.forEach(mainData, (e) => {
  _.forEach(e.data.ourBuff, (x) => {
    if (buffMap.has(x.id)) {
      _.assign(x, buffMap.get(x.id));
    }
  });
  _.forEach(e.data.foeBuff, (x) => {
    if (buffMap.has(x.id)) {
      _.assign(x, buffMap.get(x.id));
    }
  });
  e.data.selfBuff = _.map(e.data.selfBuff, (x) => {
    if (buffMap.has(x)) {
      x = buffMap.get(x);
    }
    return x;
  });
  let id = e.data.id;
  if (skillMap.has(id)) {
    _.assign(e.data, skillMap.get(id));
  }
});

fs.writeFileSync(outputFileName, JSON.stringify(mainData));
